home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr28 / reslt2.zip / RESULTS.PAS < prev   
Pascal/Delphi Source File  |  1993-03-19  |  11KB  |  403 lines

  1. PROGRAM CNEResults;
  2.   (* Show progress on Novell's CNE Assessment Test V2.1. *)
  3.  
  4.  
  5.   (***************************************************************************)
  6.   (*    Input : CNE~RSP.DAT - Response file to the CNE assessment Test.      *)
  7.   (*    Output : RESULTS.RPT - An ASCII file which can be viewed or printed. *)
  8.   (***************************************************************************)
  9.  
  10.  
  11.   (********************************************************************************************)
  12.   (* INPUT RECORD LOOKS LIKE THIS (view used by RESULTS V1.00):                               *)
  13.   (* CNE Assessment Test 2.0 :                                                                *)
  14.   (* ┌───┬──────────┬───┬─────────┬─────┬───┬─────────┬───┬───────┬────────┬───────┬────────┐ *)
  15.   (* │0Ch│FIRST_NAME│20h│LAST_NAME│0007h│63h│TEST_NAME│63h│SEC_NUM│00h..00h│ANSWERS│20h..20h│ *)
  16.   (* └───┴──────────┴───┴─────────┴─────┴───┴─────────┴───┴───────┴────────┴───────┴────────┘ *)
  17.   (********************************************************************************************)
  18.  
  19.  
  20.   (***********************************************************************************************************************)
  21.   (* CNE Assessment Test 2.1 (view used by RESULTS V2.10) :                                                              *)
  22.   (* ┌───┬──────────┬───┬─────────┬────────────────┬───┬─────────┬───┬───────┬────────────────────────┬───────┬────────┐ *)
  23.   (* │0Ch│FIRST_NAME│20h│LAST_NAME│non-(upperalpha)│63h│TEST_NAME│63h│SEC_NUM│non-(upperalpha/numeric)│ANSWERS│20h..20h│ *)
  24.   (* └───┴──────────┴───┴─────────┴────────────────┴───┴─────────┴───┴───────┴────────────────────────┴───────┴────────┘ *)
  25.   (*                              ├>   2  bytes   <┤                         ├>       10  bytes      <┤                  *)
  26.   (***********************************************************************************************************************)
  27.  
  28.  
  29.   (**********************************************************************************)
  30.   (* VERSION HISTORY :                                                              *)
  31.   (**********************************************************************************)
  32.   (* V1.00 2/16/92 - Initial version. Displays name, test, section, test results    *)
  33.   (*                    (whether correct answer or choice was incorrect, and score. *)
  34.   (*                 Author : Eric J.G. Bonnell 73500,3250.                         *)
  35.   (**********************************************************************************)
  36.   (* V2.10 3/4/92 - Fix for Assessment Test V2.1. Seems to be compatable with 2.0.  *)
  37.   (*                 Contributor : Eric J.G. Bonnell 73500,3250.                    *)
  38.   (**********************************************************************************)
  39.   (* V2.11 3/15/92 - Gives "File Not Found" message when no CNE~RSP.DAT.            *)
  40.   (*                 Will not bomb if no questions found. Instead, will report      *)
  41.   (*                    0 questions and block out percentage with '***'             *)
  42.   (*                    (i.e. no division by zero).
  43.   (*                 Contributor : Eric J.G. Bonnell 73500,3250.                    *)
  44.   (**********************************************************************************)
  45.   (* !!!!! NEXT Version Changes Go Here !!!!!!!!!                                   *)
  46.   (**********************************************************************************)
  47.  
  48.  
  49. USES
  50.      Dos,
  51.      Crt;
  52.        (* Standard I/O *)
  53.  
  54.  
  55. CONST
  56.      NUL : Char = #$00;
  57.      Preamble : Char = #$0C;
  58.      Space : Char = #$20;
  59.      ResponseHeader : Char = #$07;
  60.      Letter_c : Char = #$63;
  61.  
  62.      NessessaryCredits
  63.         = 'Compiled Using Turbo Pascal V6.0 (c) 1983,90 Borland International, Inc.';
  64.  
  65.  
  66. VAR
  67.    InFile : Text;
  68.      (* CNE~RSP.DAT *)
  69.    OutFile : Text;
  70.      (* RESULTS.RPT *)
  71.  
  72.  
  73. PROCEDURE Salutations;
  74.   (* Write an opening message on the screen. *)
  75. BEGIN
  76.    WriteLn(ParamStr(0),' - CNE Assessment Test V2.x Results.');
  77.    WriteLn('   V2.11 (c) 1992  Eric J.G. Bonnell  73500,3250.');
  78.    WriteLn
  79. END (* Salutations *);
  80.  
  81.  
  82. PROCEDURE Goodbyes;
  83.   (* Let user know it is done. *)
  84. BEGIN
  85.    WriteLn('Finished. Results are recorded in RESULTS.RPT.');
  86.    WriteLn
  87. END (* GoodByes *);
  88.  
  89.  
  90. FUNCTION IsAlpha(C : Char) : Boolean;
  91.   (* True if C is alphabetic. *)
  92. BEGIN
  93.    IsAlpha := C IN ['A'..'Z','a'..'z']
  94. END (* IsAlpha *);
  95.  
  96.  
  97. FUNCTION IsNumeric(C : Char) : Boolean;
  98.   (* True if C is a decimal digit. *)
  99. BEGIN
  100.    IsNumeric:= C IN ['0'..'9']
  101. END (* IsNumeric *);
  102.  
  103.  
  104. FUNCTION IsPreamble(C : Char) : Boolean;
  105.   (* True if C is 0Ch. *)
  106. BEGIN
  107.    IsPreamble:= C = Preamble
  108. END (* IsPreamble *);
  109.  
  110.  
  111. FUNCTION IsSpace(C : Char) : Boolean;
  112.   (* True if C is 20h. *)
  113. BEGIN
  114.    IsSpace := C = Space
  115. END (* IsSpace *);
  116.  
  117.  
  118. FUNCTION IsNul(C : Char) : Boolean;
  119.   (* True if C is 00h. *)
  120. BEGIN
  121.    IsNul := C = NUL
  122. END (* IsNul *);
  123.  
  124.  
  125. FUNCTION IsCntrl(C : Char) : Boolean;
  126.   (* True if C is not alphanumeric (not nessessarily a control character). *)
  127. BEGIN
  128.    IsCntrl := NOT IsAlpha(C) AND NOT IsNumeric(C)
  129. END (* IsCntrl *);
  130.  
  131.  
  132. FUNCTION IsResponseHeader(C : Char) : Boolean;
  133.   (* True if C iss 07h. *)
  134. BEGIN
  135.    IsResponseHeader := C = ResponseHeader
  136. END (* IsResponseHeader *);
  137.  
  138.  
  139. FUNCTION IsLetter_c(C : Char) : Boolean;
  140.   (* True if C is a lowercase letter 'c'. *)
  141. BEGIN
  142.    IsLetter_c := C = Letter_c
  143. END (* IsLetter_c *);
  144.  
  145.  
  146. FUNCTION IsNonUpperAlpha(C : Char) : Boolean;
  147.    (* True if C is not capital letter. *)
  148. BEGIN
  149.    IsNonUpperAlpha := NOT (C IN ['A'..'Z'])
  150. END (* IsNonUpperAlpha *);
  151.  
  152.  
  153. FUNCTION UpperCase(S : String) : String;
  154.   (* Convert S to all upper case characters. *)
  155. VAR
  156.    I : 0..255;
  157. BEGIN
  158.    I := Length(S);
  159.    WHILE I > 0 DO
  160.       BEGIN
  161.          S[I] := UpCase(S[I]);
  162.          Dec(I)
  163.       END;
  164.    UpperCase := S
  165. END (* UpperCase *);
  166.  
  167.  
  168. FUNCTION NoMore(VAR F : Text) : Boolean;
  169.   (* True if end-of-file found, otherwise found next record. *)
  170. VAR
  171.    C : Char;
  172. BEGIN
  173.    C := #$FF;
  174.    REPEAT
  175.       Read(F,C);
  176.       NoMore := EoF(F)
  177.    UNTIL IsPreamble(C) OR EoF(F)
  178. END (* NoMore *);
  179.  
  180.  
  181. PROCEDURE OpenFiles(VAR F,
  182.                     O : Text);
  183. VAR
  184.    S : SearchRec;
  185.   (* Open input and output files. *)
  186. BEGIN
  187.    FindFirst('CNE~RSP.DAT',AnyFile,S);
  188.    IF DosError <> 0 THEN
  189.       BEGIN
  190.          WriteLn('CNE~RSP.DAT file not found!');
  191.          Halt(1)
  192.       END;
  193.    Assign(F,'CNE~RSP.DAT');
  194.    ReSet(F);
  195.    Assign(O,'RESULTS.RPT');
  196.    ReWrite(O)
  197. END (* OpenFiles *);
  198.  
  199.  
  200. PROCEDURE CloseFiles(VAR F,
  201.                      O : Text);
  202.   (* Close input and output files. *)
  203. BEGIN
  204.    Close(F);
  205.    Close(O)
  206. END (* CloseFiles *);
  207.  
  208.  
  209. FUNCTION FirstName(VAR F : Text) : String;
  210.   (* Retrieve FIRST_NAME from current record in file F. *)
  211. VAR
  212.    S : String;
  213.    C : Char;
  214. BEGIN
  215.    S := '';
  216.    C := #$00;
  217.    WHILE (NOT EoF(F)) AND (NOT IsSpace(C)) DO
  218.       BEGIN
  219.          Read(F,C);
  220.          S[0] := Chr(Ord(S[0]) + 1);
  221.          S[Ord(S[0])] := C
  222.       END;
  223.    FirstName := UpperCase(S)
  224. END (* FirstName *);
  225.  
  226.  
  227. FUNCTION LastName(VAR F : Text) : String;
  228.   (* Retrieve LAST_NAME from current record in file F. *)
  229. VAR
  230.    S : String;
  231.    C : Char;
  232. BEGIN
  233.    S := '';
  234.    C := #$FF;
  235.    Read(F,C);
  236.    WHILE (NOT EoF(F)) AND NOT IsNonUpperAlpha(C) DO
  237.       BEGIN
  238.          S[0] := Chr(Ord(S[0]) + 1);
  239.          S[Ord(S[0])] := C;
  240.          Read(F,C)
  241.       END;
  242.    LastName := UpperCase(S)
  243. END (* LastName *);
  244.  
  245.  
  246. FUNCTION TestName(VAR F : Text) : String;
  247.   (* Retrieve TEST_NAME from current record in file F. *)
  248. VAR
  249.    S : String;
  250.    I : 0..3;
  251.    C : Char;
  252. BEGIN
  253.    S := '';
  254.    C := #$00;
  255.    FOR I := 1 TO 3 DO
  256.       Read(F,C);
  257.    FOR I := 1 TO 3 DO
  258.       BEGIN
  259.          S[0] := Chr(Ord(S[0]) + 1);
  260.          S[Ord(S[0])] := C;
  261.          Read(F,C)
  262.       END;
  263.    TestName := UpperCase(S)
  264. END (* TestName *);
  265.  
  266.  
  267. FUNCTION SectionNumber(VAR F : Text) : Integer;
  268.   (* Retrieve SEC_NUM from current record in file F. *)
  269. VAR
  270.    Code : Integer;
  271.    Value : Integer;
  272.    S : String;
  273.    C : Char;
  274. BEGIN
  275.    S := '';
  276.    C := #$00;
  277.    WHILE (NOT Eof(F)) AND IsResponseHeader(C) DO
  278.       Read(F,C);
  279.    Read(F,C);
  280.    FOR Code := 1 TO 2 DO
  281.       BEGIN
  282.          S[0] := Chr(Ord(S[0]) + 1);
  283.          S[Ord(S[0])] := C;
  284.          Read(F,C)
  285.       END;
  286.    Val(S,Value,Code);
  287.    SectionNumber := Value
  288.  
  289. END (* SectionNumber *);
  290.  
  291.  
  292. FUNCTION QuestionStatus(VAR F : Text;
  293.                         VAR Q : Integer;
  294.                         VAR I : Integer;
  295.                         VAR N : Integer;
  296.                         VAR C : Char) : String;
  297.   (* Determine the results of Question Q in current record in F.
  298.      tally I correct responces for N total questions, passing back
  299.      the next field C in record. *)
  300. VAR
  301.    S : String;
  302.    T : String;
  303. BEGIN
  304.    S := '';
  305.    Str(Q,S);
  306.    IF Length(S) < 2 THEN
  307.       S := ' ' + S;
  308.    T[0] := Chr(1);
  309.    T[1] := C;
  310.    T := UpperCase(T);
  311.    Inc(N);
  312.    IF IsNumeric(C) THEN
  313.       BEGIN
  314.          Inc(I);
  315.          QuestionStatus := 'Question ' + S + ' was answered correctly.'
  316.       END
  317.    ELSE
  318.       QuestionStatus := 'Question ' + S + ' was incorrectly answered!   [' + T + ']';
  319.    Inc(Q);
  320.    Read(F,C)
  321. END (* QuestionStatus *);
  322.  
  323.  
  324. PROCEDURE ListEm(VAR F : Text;
  325.                  VAR O : Text;
  326.                  VAR I : Integer;
  327.                  VAR N : Integer);
  328.   (* Step through all the responses until there are no more in F.
  329.      Write a status for the response in O and tally I correct responses
  330.      for N total questions. *)
  331. VAR
  332.    C : Char;
  333.    Q : Integer;
  334.    Waste : 0..10;
  335. BEGIN
  336.    Q := 1;
  337.    C := #$FF;
  338.    C := #$FF;
  339.    FOR Waste := 1 TO 10 DO
  340.       Read(F,C);
  341.    WHILE (NOT EoF(F)) AND (NOT IsSpace(C)) DO
  342.       WriteLn(O,QuestionStatus(F,Q,I,N,C))
  343. END (* ListEm *);
  344.  
  345.  
  346. PROCEDURE DoIt(VAR F,
  347.                O : Text);
  348.   (* List out the information in file F into ASCII text output file O. *)
  349. VAR
  350.    Percentage : Real;
  351.    InvalPercent : String;
  352.    I : Integer;
  353.    N : Integer;
  354. BEGIN
  355.    WriteLn(O,'────────────── CNE Assessment Test Results ───────────────');
  356.  
  357.    WHILE NOT NoMore(F) DO
  358.       BEGIN
  359.          Percentage := 0.0;
  360.          I := 0;
  361.          N := 0;
  362.  
  363.          WriteLn(O);
  364.          WriteLn(O,'TESTED : ',FirstName(F),' ',LastName(F),'.');
  365.          WriteLn(O);
  366.          WriteLn(O,'COURSE : ',TestName(F),'  SECTION : ',SectionNumber(F));
  367.          WriteLn(O);
  368.          ListEm(F,O,I,N);
  369.          IF N = 0 THEN
  370.             InvalPercent := '***'
  371.          ELSE
  372.             Percentage := I / N * 100;
  373.          WriteLn(O);
  374.          WriteLn(O);
  375.          IF N = 0 THEN
  376.             WriteLn(O,'SCORE :   ',I,' Correct out of ',N,' = ',InvalPercent,'%.')
  377.          ELSE
  378.             WriteLn(O,'SCORE :   ',I,' Correct out of ',N,' = ',Percentage:5:2,'%.');
  379.          WriteLn(O);
  380.          WriteLn(O,'──────────────────────────────────────────────────────────')
  381.       END
  382.  
  383. END (* DoIt *);
  384.  
  385.  
  386. BEGIN (* main *)
  387.  
  388.    Salutations;
  389.    OpenFiles(InFile,OutFile);
  390.  
  391.    DoIt(InFile,OutFile);
  392.  
  393.    CloseFiles(InFile,OutFile);
  394.    Goodbyes
  395.  
  396. END.
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.